package com.example.weather.main

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.example.library_base.base.BaseEventHandler
import com.example.library_base.router.UserRouterPath
import com.example.library_base.router.WeatherRouterPath
import com.example.weather.R
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.qualifiers.ActivityContext
import javax.inject.Inject

@Module
@InstallIn(ActivityComponent::class)
class MainEventHandler @Inject constructor(
    @ActivityContext val mContext: Context
): BaseEventHandler(){

    //跳转到查询天气页面
    fun skipTodayWeather(){
        ARouter.getInstance().build(WeatherRouterPath.WEATHER_TODAY_WEATHER)
            .withTransition(R.anim.right_in, R.anim.left_out)
            .navigation(mContext)
    }

    //跳转到美女页面
    fun skipGirl(){
        ARouter.getInstance().build(WeatherRouterPath.WEATHER_GIRL)
            .withTransition(R.anim.right_in, R.anim.left_out)
            .navigation(mContext)
    }

    //跳转到插入数据页面
    fun skipInsertData(){
        ARouter.getInstance().build(WeatherRouterPath.WEATHER_INSERT_DATA)
            .withString("name", "name")
            .withTransition(R.anim.right_in, R.anim.left_out)
            .navigation(mContext)
    }

    //跳转到插入数据页面
    fun skipTitle(){
        ARouter.getInstance().build(WeatherRouterPath.WEATHER_TITLE)
            .withString("title", "title")
            .withTransition(R.anim.right_in, R.anim.left_out)
            .navigation(mContext)
    }

    //跳转到插入数据页面
    fun skipTitleCustom(){
        ARouter.getInstance().build(WeatherRouterPath.WEATHER_TITLE_CUSTOM)
            .withTransition(R.anim.right_in, R.anim.left_out)
            .navigation(mContext, object: NavigationCallback{
                //找到了页面
                override fun onFound(postcard: Postcard?) {
                }

                //找不到页面
                override fun onLost(postcard: Postcard?) {
                }

                //跳转成功
                override fun onArrival(postcard: Postcard?) {
                }

                //被拦截了
                override fun onInterrupt(postcard: Postcard?) {
                    //跳转到登陆，
                    //把参数和path都传递到登陆页，登陆完成后再跳转
                    val path = postcard?.path
                    val extras = postcard?.extras
                    ARouter.getInstance()
                        .build(UserRouterPath.USER_LOGIN)
                        .with(extras)
                        .withString("path", path)
                        .navigation()
                }
            })
    }
}